package testPaperJBFX;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.lancooznbk.R;
import com.example.lancooznbk.model.result.BaseReviewItemEntity;
import com.example.lancooznbk.presenter.PaperDef;
import com.example.lancooznbk.view.base.BaseActivity;
import com.example.lancooznbk.view.base.BaseFragment;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.example.lancooznbk.view.widget.EmptyMainLayout;
import com.example.lancooznbk.view.widget.LoadingDialog;
import com.lancoo.dictionary.activity.DictionaryActicity;
import com.lancoo.reviewsystem.utils.ToastUtils;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import lancooControl.AndroidBug5497Workaround;
import lancooControl.BackPreservationDialog;
import lancooControl.Control;
import lancooControl.NoFastClickUtils;
import lancooControl.PopupWindowMoreFunction;
import lancooControl.SubmitDialog;
import lancooUpLoad.ChangeStuFavouritePresenter;
import lancooUpLoad.DataPackage;
import lancooUpLoad.PaperInfor;
import lancooUpLoad.SavePresenter;
import lancooUpLoad.SubmitDataJson;
import lancooUpLoad.SubmitPresenter;
import testPaperJBFX.jsonBasicReview.BasicReviewJson;
import testPaperJBFX.jsonBasicReview.BasicReviewPresenter;

import static lancooUpLoad.PaperInfor.isfirstSubmit;


/**
 * Created by Administrator on 2017/6/7/007.
 */

public class BasicReviewPaperActivity extends BaseActivity implements View.OnLayoutChangeListener,ILoadPaperView<BasicReviewJson>{

    private RelativeLayout RLayoutBackMenu;//返回按钮菜单
//    private TextView TvBack;//返回按钮
    private RelativeLayout RLayoutAnswerNumberMenu;//答题号菜单
    private RelativeLayout RLayoutSubmitMenu;//提交菜单
    private TextView TvSubmit;//提交文字
    private RelativeLayout RLayoutMoreFouctionMenu;//更多功能菜单
    private TextView TvTimeMeter;//计时器

    public static ViewPager VpBasicReviewPaper;
    private BasicReviewPaperFragmentAdapter mAdapter;


    private BasicReviewAnswerSheet mBasicReviewAnswerSheet;

    public static int lastBigViewPage =0;
    public static int currentBigViewPage = 0;

    BasicReviewPresenter mBasicReviewPresenter;
    public static BasicReviewJson InforBasicReview;


    //Activity最外层的Layout视图
    private View activityRootView;
    //屏幕高度
    private int screenHeight = 0;
    //软件盘弹起后所占高度阀值
    private int keyHeight = 0;

    private BaseReviewItemEntity.BaseReviewItemBean mEntity;
    public static final  String PAPER_ENTITY = "paperEntity";
    public static final String PAPER_FROM = "paperFrom";

    public int mQuesOrPaperFrom;

    private LoadingDialog mLoadingDialog;




    public  static void launch(BaseFragment mContext, BaseReviewItemEntity.BaseReviewItemBean entity, @PaperDef.PaperFrom int quesOrPaperFrom){
        Log.e("======PaperID==========",entity.getTestPaperID());
        Log.e("======QuesFrom========", String.valueOf(entity.getPaperFrom()));
        PaperInfor.PaperID = entity.getTestPaperID();
        PaperInfor.QuesFrom = entity.getPaperFrom();
        PaperInfor.schoolId=UserInfo.SchoolId;
        PaperInfor.term="";
        PaperInfor.StuID = UserInfo.StuId;

        PaperInfor.SubjectID = UserInfo.SubjectId;
        PaperInfor.StageNo = UserInfo.StageNo;
        Bundle bundle = new Bundle();
        bundle.putSerializable(PAPER_ENTITY,entity);
        bundle.putInt(PAPER_FROM,quesOrPaperFrom);
        Intent intent = new Intent(mContext.getContext(), BasicReviewPaperActivity.class);
        intent.putExtras(bundle);
        mContext.startActivityForResult(intent,1);
    }

    @Override
    public int attachLayoutRes() {
        return R.layout.activity_test_paper;
    }

    @Override
    protected void initViews() {
        Log.e("====10101======", "==initViews==");
        AndroidBug5497Workaround.assistActivity(this);
        mBasicReviewPresenter = new BasicReviewPresenter(this);
        Bundle bundle = getIntent().getExtras();
        if (bundle != null){
            mEntity = (BaseReviewItemEntity.BaseReviewItemBean) bundle.getSerializable(PAPER_ENTITY);
            mQuesOrPaperFrom = bundle.getInt(PAPER_FROM);
        }

        //核心代码.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

        currentBigViewPage = 0;

        initView();

        activityRootView = findViewById(R.id.main);
        //获取屏幕高度
        screenHeight = this.getWindowManager().getDefaultDisplay().getHeight();
        //阀值设置为屏幕高度的1/3
        keyHeight = screenHeight/3;

    }

    @Override
    protected void updateViews(boolean isRefresh) {
        Log.e("====10101======", "==updateViews==");
        isfirstSubmit = false;
        mBasicReviewPresenter.getData(isRefresh);
    }

    /*
* 开启计时定时器
* */
    private  int paperTimeLong = 0;
    private int  LastTimer = 0;//记前一次时长
    private int recLen = 0;//当前时长
    Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            recLen++;
            TvTimeMeter.setText(getStringTime(LastTimer+recLen));
            paperTimeLong = LastTimer+recLen;
            handler.postDelayed(this, 1000);
        }
    };

    private String getStringTime(int cnt) {
        int hour = cnt/3600;
        int min = cnt % 3600 / 60;
        int second = cnt % 60;
        if(hour>0){
            return String.format(Locale.CHINA,"%02d:%02d:%02d",hour,min,second);
        }else{
            return String.format(Locale.CHINA,"%02d:%02d",min,second);
        }
    }



    /*
    * 初始化界面控件
    * */
    private void initView(){

        mEmptyViewLayout = (EmptyMainLayout) findViewById(R.id.layout_loading);
        /*
        * 返回按钮菜单相关设置
        * */
//        TvBack = (TextView) findViewById(R.id.textview_back);
        RLayoutBackMenu = (RelativeLayout) findViewById(R.id.rlayout_back_menu);
        RLayoutBackMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(InforBasicReview!=null) {
                    if (InforBasicReview.getState() != 2) {
                        backPreservationDialog();
                    } else {
                        finish();
                    }
                }else{
                    finish();
                }
            }
        });

        /*
        * 答题号按钮菜单相关信息
        * */
        RLayoutAnswerNumberMenu = (RelativeLayout) findViewById(R.id.rlayout_answer_number_menu);
        RLayoutAnswerNumberMenu.setVisibility(View.INVISIBLE);
        RLayoutAnswerNumberMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(InforBasicReview!=null) {
                    if (NoFastClickUtils.isFastClick()) {
                        //快速点击后的逻辑，可以提示用户点击太快，休息一会
                        Toast.makeText(getApplicationContext(), "点击太快，休息一会", Toast.LENGTH_SHORT).show();

                    } else {
                        //正常点击的逻辑
                        Fragment fragment = (Fragment) ((BasicReviewPaperFragmentAdapter) VpBasicReviewPaper.getAdapter()).instantiateItem(VpBasicReviewPaper,VpBasicReviewPaper.getCurrentItem());
                        ViewPager childViewPage = (ViewPager) fragment.getView().findViewById(R.id.viewpage_answer);
                            mBasicReviewAnswerSheet = new BasicReviewAnswerSheet(BasicReviewPaperActivity.this,VpBasicReviewPaper.getCurrentItem(),childViewPage.getCurrentItem());
                            mBasicReviewAnswerSheet.setClippingEnabled(false);//使popupwindow显示为全屏
                            mBasicReviewAnswerSheet.showAtLocation(BasicReviewPaperActivity.this.findViewById(R.id.main), Gravity.TOP, 0, 0);
                    }
                }else{
                    Toast.makeText(getApplicationContext(), "数据加载中，请稍后重试...", Toast.LENGTH_SHORT).show();
                }

            }
        });

        /*
        * 提交按钮菜单相关信息
        * */
        RLayoutSubmitMenu = (RelativeLayout) findViewById(R.id.rlayout_submit_menu);
        RLayoutSubmitMenu.setVisibility(View.INVISIBLE);
        RLayoutSubmitMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(InforBasicReview.getState()!=2){
                    //执行提交操作
                    submitDialog();
                }
//                else{
//                    //进入辅导
//                    if(isCouldTrain){
//                        PaperInfor.QuesID = InforBasicReview.getPaperContent().get(currentBigViewPage).getQuesID();
//                        WrongQuesPaperActivity.launch(null,BasicReviewPaperActivity.this,PaperInfor.QuesID,PaperInfor.QuesFrom,PaperDef.FROM_BASE_REVIEW_WRONG);
//                    }else{
////                        Toast.makeText(getApplicationContext(),"灰色",Toast.LENGTH_SHORT).show();
//                    }
//                }

            }
        });
        TvSubmit = (TextView) findViewById(R.id.textview_submit);

        /*
        * 更多功能按钮菜单相关信息
        * */
        RLayoutMoreFouctionMenu = (RelativeLayout) findViewById(R.id.rlayout_more_fouction_menu);
        RLayoutMoreFouctionMenu.setVisibility(View.INVISIBLE);
        RLayoutMoreFouctionMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(getApplicationContext(),"更多功能菜单",Toast.LENGTH_SHORT).show();
                if(InforBasicReview!=null) {
                    initPopupWindowMoreFunction();
                }else {
                    Toast.makeText(getApplicationContext(),"数据加载中，请稍后重试...",Toast.LENGTH_SHORT).show();
                }
            }
        });

        /*
        * 计时器显示
        * */
        TvTimeMeter = (TextView) findViewById(R.id.tv_time_meter);
        TvTimeMeter.setVisibility(View.INVISIBLE);

        VpBasicReviewPaper = (ViewPager) findViewById(R.id.viewpager);



    }

    /*********************
     * ******************
     *实现试卷明细解析
     * *****************
     ******************/
    /************************************************************************************************************************/

    @Override
    public void loadData(BasicReviewJson data) {

        Log.e("====10101======", "==loadData==");
        InforBasicReview =data;

        PaperInfor.QuesBrief = InforBasicReview.getPaperContent().get(0).getTheme();
        PaperInfor.TypeID = InforBasicReview.getPaperContent().get(0).getTypeID();

        //这里因为是3.0一下版本，所以需继承FragmentActivity，通过getSupportFragmentManager()获取FragmentManager
        //3.0及其以上版本，只需继承Activity，通过getFragmentManager获取事物
        FragmentManager fm = getSupportFragmentManager();
        //初始化自定义适配器MyFragmentPageAdapter
        mAdapter =  new BasicReviewPaperFragmentAdapter(fm);
        MyOnPageChangeListener myOnPageChangeListener = new MyOnPageChangeListener();
        VpBasicReviewPaper.setOnPageChangeListener(myOnPageChangeListener);
        //绑定自定义适配器
        if(data.getState() == 2){
            mAdapter.paperHasSubmit();
        }


        VpBasicReviewPaper.setAdapter(mAdapter);

        /*
        * 若为非已提交状态显示时间并开启计时功能，若为已提交状态则只显示已学习时长
        * */
        LastTimer = data.getDuration();//获取已作答时长

        if(data.getState()!=2) {
            handler.postDelayed(runnable, 1000);
            RLayoutSubmitMenu.setVisibility(View.VISIBLE);
            TvSubmit.setText("提交");
        }else{
            TvTimeMeter.setText(getStringTime(LastTimer));
            RLayoutSubmitMenu.setVisibility(View.GONE);
        }

        if(InforBasicReview!=null){
            RLayoutAnswerNumberMenu.setVisibility(View.VISIBLE);
            RLayoutMoreFouctionMenu.setVisibility(View.VISIBLE);
            TvTimeMeter.setVisibility(View.VISIBLE);
        }

    }

    @Override
    public void loadComplete(boolean hasComplete) {

    }

    @Override
    public void openExamReportDialog() {

        Fragment fragment = (Fragment) ((BasicReviewPaperFragmentAdapter) VpBasicReviewPaper.getAdapter()).instantiateItem(VpBasicReviewPaper,VpBasicReviewPaper.getCurrentItem());
        ViewPager childViewPage = (ViewPager) fragment.getView().findViewById(R.id.viewpage_answer);
            mBasicReviewAnswerSheet = new BasicReviewAnswerSheet(BasicReviewPaperActivity.this,VpBasicReviewPaper.getCurrentItem(),childViewPage.getCurrentItem());
            mBasicReviewAnswerSheet.setClippingEnabled(false);//使popupwindow显示为全屏
            mBasicReviewAnswerSheet.showAtLocation(BasicReviewPaperActivity.this.findViewById(R.id.main), Gravity.TOP, 0, 0);
            updateViews(true);
    }

    @Override
    public void updatingResult(boolean isSucceed) {
        mLoadingDialog.dismiss();
        if (isSucceed){
        }else {
            ToastUtils.showShort("提交失败");
        }
    }

    public  LoadingDialog getLoadingDialog(){
        return mLoadingDialog;
    }

    @Override
    public RxAppCompatActivity getHolderActivity() {
        return null;
    }



    /************************************************************************************************************************/
    /*
    * LazyViewPage切换事件监听
    * */
    class MyOnPageChangeListener implements ViewPager.OnPageChangeListener {

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageSelected(int arg0) {

            /*
            * 绑定当前题目小页码
            * */
            lastBigViewPage = currentBigViewPage;

            /*
            * 获取试卷明细相关信息
            * */
            /*************************************************************************************************************************/
            /*************************************************************************************************************************/
            /*************************************************************************************************************************/
            if(InforBasicReview.getState()!=2) {
                slideSave(lastBigViewPage, false);
            }
            /*************************************************************************************************************************/
            /*************************************************************************************************************************/
            /*************************************************************************************************************************/
            currentBigViewPage = arg0;
            Log.e("=======bigViewPage====","===AA==="+currentBigViewPage);

            /*
            * 隐藏软键盘
            * */
            HideKeyboard();

        }

    }


    //隐藏虚拟键盘:Fragment进行切换的时候使用
    public  void HideKeyboard() {
        /**隐藏软键盘**/
        View viewK = this.getWindow().peekDecorView();
        if(viewK != null){
            InputMethodManager inputmanger = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputmanger.hideSoftInputFromWindow(viewK.getWindowToken(), 0);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    /*
    * 监听系统home事件
    * */
    @Override
    protected void onUserLeaveHint() {
        super.onUserLeaveHint();
        System.out.println("onUserLeaveHint");
    }

    /*
    * 监听系统返回事件
    * */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {

            if(InforBasicReview!=null) {
                if (InforBasicReview.getState() != 2) {
                    backPreservationDialog();
                } else {
                    finish();
                }
            }else{
                finish();
            }

            return false;
        }
        return false;
    }


    /*
    *获取题型
    * f：作文  大Z：听力简答  大S：听力填空  E：听力选择  大X：阅读简答  D：阅读选择  K：阅读判断  Q：阅读填空
    * H：短文匹配  大C：完形选择  大O：句子填空  G：对话匹配  g：翻译题  d：看图写句子  A；单选题
    * */
    private  String getQuesType(int postion){
        String strTypeID = BasicReviewPaperActivity.InforBasicReview.getPaperContent().get(postion).getTypeID();
        String strQuesTypeName = "";
        if(strTypeID.equals("f")){
            strQuesTypeName = "作文";
        }else if(strTypeID.equals("Z")){
            strQuesTypeName = "听力简答";
        }else if(strTypeID.equals("S")){
            strQuesTypeName = "听力填空";
        }else if(strTypeID.equals("E")){
            strQuesTypeName = "听力选择";
        }else if(strTypeID.equals("X")){
            strQuesTypeName = "阅读简答";
        }else if(strTypeID.equals("D")){
            strQuesTypeName = "阅读选择";
        }else if(strTypeID.equals("K")){
            strQuesTypeName = "阅读判断";
        }else if(strTypeID.equals("Q")){
            strQuesTypeName = "阅读填空";
        }else if(strTypeID.equals("m")){
            strQuesTypeName = "匹配题";
        }else if(strTypeID.equals("C")){
            strQuesTypeName = "完形选择";
        }else if(strTypeID.equals("O")){
            strQuesTypeName = "句子填空";
        }else if(strTypeID.equals("g")){
            strQuesTypeName = "翻译题";
        }else if(strTypeID.equals("d")){
            strQuesTypeName = "看图写句子";
        }else if(strTypeID.equals("A")){
            strQuesTypeName = "单选题";
        }else if(strTypeID.equals("T")){
            strQuesTypeName = "翻译填空";
        }else if(strTypeID.equals("P")){
            strQuesTypeName = "短文填空";
        }else if(strTypeID.equals("N")){
            strQuesTypeName = "词汇填空";
        }
        return  strQuesTypeName;
    }

    /******************************************更多功能popupwindow****************************************************/

    private PopupWindowMoreFunction mPopupWindowMoreFunction;
    private void initPopupWindowMoreFunction(){
        if (mPopupWindowMoreFunction == null) {
            //自定义的单击事件
            OnClickLintener paramOnClickListener = new OnClickLintener();
            mPopupWindowMoreFunction = new PopupWindowMoreFunction(this, paramOnClickListener, Control.dip2px(this,140), Control.dip2px(this,80));
            //监听窗口的焦点事件，点击窗口外面则取消显示
            mPopupWindowMoreFunction.getContentView().setOnFocusChangeListener(new View.OnFocusChangeListener() {

                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if (!hasFocus) {
                        mPopupWindowMoreFunction.dismiss();
                    }
                }
            });
        }

        if(!InforBasicReview.getPaperContent().get(currentBigViewPage).getTheme().equals("")) {
            PaperInfor.QuesBrief = InforBasicReview.getPaperContent().get(currentBigViewPage).getTheme();
        }else{
            PaperInfor.QuesBrief = InforBasicReview.getPaperContent().get(currentBigViewPage).getQueList().get(0).getItemContent();
        }
        PaperInfor.QuesID = InforBasicReview.getPaperContent().get(currentBigViewPage).getQuesID();
        PaperInfor.TypeID = InforBasicReview.getPaperContent().get(currentBigViewPage).getTypeID();

        Log.e("======isIsLike========","===00=="+InforBasicReview.getPaperContent().get(currentBigViewPage).isIsLike());
        Log.e("======QuesBrief========","===00=="+PaperInfor.QuesBrief);
        Log.e("======QuesID========","===00=="+PaperInfor.QuesID);
        Log.e("======TypeID========","===00=="+PaperInfor.TypeID);

        //显示当前试题的收藏情况
        if(!InforBasicReview.getPaperContent().get(currentBigViewPage).isIsLike()) {
            PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_unfocus);
            PopupWindowMoreFunction.TvDifficultQuestion.setText("加入收藏");
            PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.white));
        }else if(InforBasicReview.getPaperContent().get(currentBigViewPage).isIsLike()){
            PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_focus);
            PopupWindowMoreFunction.TvDifficultQuestion.setText("取消收藏");
            PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.yellow));
        }

//设置默认获取焦点
        mPopupWindowMoreFunction.setFocusable(true);
//以某个控件的x和y的偏移量位置开始显示窗口
        mPopupWindowMoreFunction.showAsDropDown(RLayoutMoreFouctionMenu, Control.dip2px(this,-120), Control.dip2px(this,15));
//如果窗口存在，则更新
        mPopupWindowMoreFunction.update();
    }
    class OnClickLintener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.layout_dictionary:
                    System.out.println("=======电子词典=========");
                    mPopupWindowMoreFunction.dismiss();
                    startActivity(new Intent(getApplicationContext(), DictionaryActicity.class));
                    break;
                case R.id.layout_difficult_question:
                    System.out.println("=======收藏与否=========");
                    if(!InforBasicReview.getPaperContent().get(currentBigViewPage).isIsLike()) {
                        PaperInfor.IsLike = 1;
                        InforBasicReview.getPaperContent().get(currentBigViewPage).setIsLike(true);
                        PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_focus);
                        PopupWindowMoreFunction.TvDifficultQuestion.setText("取消收藏");
                        PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.yellow));
                    }else if(InforBasicReview.getPaperContent().get(currentBigViewPage).isIsLike()){
                        PaperInfor.IsLike = 0;
                        InforBasicReview.getPaperContent().get(currentBigViewPage).setIsLike(false);
                        PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_unfocus);
                        PopupWindowMoreFunction.TvDifficultQuestion.setText("加入收藏");
                        PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.white));
                    }
                    PaperInfor.QuesID = InforBasicReview.getPaperContent().get(currentBigViewPage).getQuesID();
                    changeStuFavourite();
                    break;

                default:
                    break;
            }

        }

    }


    /*
    * 加入收藏、取消收藏
    * */
    ChangeStuFavouritePresenter mChangeStuFavouritePresenter;
    private void changeStuFavourite(){
        mChangeStuFavouritePresenter = new ChangeStuFavouritePresenter(this,mQuesOrPaperFrom);
        mChangeStuFavouritePresenter.getData(false);
    }

    /*
    * 保存单道试题作答信息
    * */
    SavePresenter mSavePresenter;
    private void saveSingleQues(boolean isFromExit){
        mSavePresenter = new SavePresenter(this,mQuesOrPaperFrom);
        mSavePresenter.getData(false,isFromExit);
    }

    /*
    * 提交试题作答信息
    * */
    SubmitPresenter mSubmitPresenter;
    private void submitTestPaper(boolean isFromExit){
        mSubmitPresenter = new SubmitPresenter(this,mQuesOrPaperFrom);
        mSubmitPresenter.getData(false,isFromExit);
    }


    /*
    * 返回保存上传答案
    * */
    public void backPreservationDialog() {
        final BackPreservationDialog mBackPreservationDialog = new BackPreservationDialog(this);
        mBackPreservationDialog.getWindow().setWindowAnimations(R.style.Dialog_Anim_Style);
        mBackPreservationDialog.show();
        mBackPreservationDialog.setClicklistener(new BackPreservationDialog.ClickListenerInterface() {

            @Override
            public void doContinueAnswer() {
                //继续作答
                mBackPreservationDialog.dismiss();

            }

            @Override
            public void doConfirmAnswer() {

                if(InforBasicReview.getState()!=2) {
                    String StuAnswerNewAll = InforBasicReview.getPaperContent().get(currentBigViewPage).getStuAnswerNewAll();
                    String StuAssessNewAll = InforBasicReview.getPaperContent().get(currentBigViewPage).getStuAssessNewAll();
                    String StuAnswerOldAll = InforBasicReview.getPaperContent().get(currentBigViewPage).getStuAnswerOldAll();
                    String StuAssessOldAll = InforBasicReview.getPaperContent().get(currentBigViewPage).getStuAssessOldAll();
                    //退出作答,保存数据上传
                    if (StuAnswerNewAll.equals(StuAnswerOldAll) && StuAssessNewAll.equals(StuAssessOldAll)) {
                        finish();
                    } else {
                        slideSave(currentBigViewPage, true);
                    }
                }else{
                    finish();
                }

                mBackPreservationDialog.dismiss();
            }

        });
    }


    /*
* 提交上传答案
* */
    public void submitDialog() {
        final SubmitDialog mSubmitDialog = new SubmitDialog(this,mQuesOrPaperFrom);
        mSubmitDialog.getWindow().setWindowAnimations(R.style.Dialog_Anim_Style);
        mSubmitDialog.show();
        mSubmitDialog.setClicklistener(new SubmitDialog.ClickListenerInterface() {

            @Override
            public void doCancle() {
                //关闭弹窗
                mSubmitDialog.dismiss();
            }

            @Override
            public void doEnsure() {
                handler.removeCallbacks(runnable);
                //关闭弹窗
                mSubmitDialog.dismiss();
                if (mLoadingDialog == null) {
                    LoadingDialog.Builder builder1=new LoadingDialog.Builder(BasicReviewPaperActivity.this)
                            .setMessage(getString(R.string.updateing))
                            .setCancelOutside(false);
                    mLoadingDialog =builder1.create();
                    mLoadingDialog.show();
                }

                addTestPaperInfor();
                submitTestPaper(true);
            }

        });
    }


    @Override
    protected void onResume() {
        super.onResume();
        //添加layout大小发生改变监听器
        activityRootView.addOnLayoutChangeListener(this);
    }

    @Override
    public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {

        if (bottom > oldBottom){
            //输入法软键盘关闭
            Log.d(">>>>>>>>>crg", "输入法软键盘关闭: ");
        } else if (bottom < oldBottom){
            //输入法软键盘打开
            Log.d(">>>>>>>>>crg", "输入法软键盘打开: ");
        }

    }

    /*******************************************************************************************************************************/
    /*******************************************************************************************************************************/
    /*******************************************************************************************************************************/

    /*
    * 滑动保存  Position = lastBigViewPage
    * 返回保存  Position = currentBigViewPage
    * */
    private void slideSave(int Position,boolean isFromExit){

        for(int i=0;i<InforBasicReview.getPaperContent().get(Position).getTotalItemCount();i++){
            if(i==0){
                PaperInfor.IsAssess = InforBasicReview.getPaperContent().get(Position).getQueList().get(0).getIsAssess();
            }else{
                PaperInfor.IsAssess = PaperInfor.IsAssess+"#$*#"+InforBasicReview.getPaperContent().get(Position).getQueList().get(i).getIsAssess();
            }
        }

        PaperInfor.Score = InforBasicReview.getPaperContent().get(Position).getScore();
        if(!InforBasicReview.getPaperContent().get(Position).getTheme().equals("")) {
            PaperInfor.QuesBrief = InforBasicReview.getPaperContent().get(Position).getTheme();
        }else{
            PaperInfor.QuesBrief = InforBasicReview.getPaperContent().get(Position).getQueList().get(0).getItemContent();
        }
        PaperInfor.QuesTotalItemCount = InforBasicReview.getPaperContent().get(Position).getTotalItemCount();//试卷总题数
        PaperInfor.TypeID = InforBasicReview.getPaperContent().get(Position).getTypeID();
        int sumImportantZSDCode = InforBasicReview.getPaperContent().get(Position).getImpKlg().size();
        String ImportantZSDCodeAll = "";
        String ImportantZSDAll = "";
        for(int i=0;i<sumImportantZSDCode;i++){
            if(i==0){
                ImportantZSDCodeAll = InforBasicReview.getPaperContent().get(Position).getImpKlg().get(i).getCode();
                ImportantZSDAll = InforBasicReview.getPaperContent().get(Position).getImpKlg().get(i).getName();
            }else {
                ImportantZSDCodeAll = ImportantZSDCodeAll + "|" + InforBasicReview.getPaperContent().get(Position).getImpKlg().get(i).getCode();
                ImportantZSDAll = ImportantZSDAll + "|" + InforBasicReview.getPaperContent().get(Position).getImpKlg().get(i).getName();
            }
        }
        PaperInfor.ImportantZSDCode = ImportantZSDCodeAll;
        PaperInfor.ImportantZSD = ImportantZSDAll;
        int sumMainZSDCode = InforBasicReview.getPaperContent().get(Position).getMainKlg().size();
        String MainZSDCodeAll = "";
        String MainZSDAll = "";
        for(int i=0;i<sumMainZSDCode;i++){
            if(i==0){
                MainZSDCodeAll = InforBasicReview.getPaperContent().get(Position).getMainKlg().get(i).getCode();
                MainZSDAll = InforBasicReview.getPaperContent().get(Position).getMainKlg().get(i).getName();
            }else {
                MainZSDCodeAll = MainZSDCodeAll + "|" + InforBasicReview.getPaperContent().get(Position).getMainKlg().get(i).getCode();
                MainZSDAll = MainZSDAll + "|" + InforBasicReview.getPaperContent().get(Position).getMainKlg().get(i).getName();
            }
        }
        PaperInfor.MainZSDCode = MainZSDCodeAll;
        PaperInfor.MainZSD = MainZSDAll;
        PaperInfor.Difficulty = InforBasicReview.getDifficulty();
        PaperInfor.TestProbablity = 0.5;
        PaperInfor.StuName = UserInfo.StuName;
        PaperInfor.QuesDuration = paperTimeLong-InforBasicReview.getDuration()+InforBasicReview.getPaperContent().get(Position).getDuration();//暂时瞎传
        InforBasicReview.getPaperContent().get(Position).setDuration(PaperInfor.QuesDuration);
        PaperInfor.QuesID = InforBasicReview.getPaperContent().get(Position).getQuesID();
        PaperInfor.StuAnswerNewAll = InforBasicReview.getPaperContent().get(Position).getStuAnswerNewAll();
        PaperInfor.StuAnswerOldAll = InforBasicReview.getPaperContent().get(Position).getStuAnswerOldAll();
        PaperInfor.StuAssessNewAll = InforBasicReview.getPaperContent().get(Position).getStuAssessNewAll();
        PaperInfor.StuAssessOldAll = InforBasicReview.getPaperContent().get(Position).getStuAssessOldAll();
        if(getQuesType(Position).equals("词汇填空")||getQuesType(Position).equals("阅读填空")||getQuesType(Position).equals("句子填空")||
                getQuesType(Position).equals("翻译填空")||getQuesType(Position).equals("短文填空")||getQuesType(Position).equals("听力填空")){

            int totalItemCountTrue = 0;
            String thisStuAnswer = "";
            String thisAnswer = "";
            String thisStuAssess = "";
            int totalItemCount = InforBasicReview.getPaperContent().get(Position).getTotalItemCount();
            int allSmallQuesItemTotalCount = 0;
            for(int i=0;i<totalItemCount;i++) {
                allSmallQuesItemTotalCount = allSmallQuesItemTotalCount + Control.backSum(
                        InforBasicReview.getPaperContent().get(Position).getQueList().get(i).getAnswer(), "$、") + 1;
            }
            for(int i=0;i<totalItemCount;i++){
                thisStuAnswer = InforBasicReview.getPaperContent().get(Position).getQueList().get(i).getStuAnswer();
                thisAnswer = InforBasicReview.getPaperContent().get(Position).getQueList().get(i).getAnswer();
                thisStuAssess = InforBasicReview.getPaperContent().get(Position).getQueList().get(i).getStuAssess();
                Log.e("=====True====","===="+thisStuAssess);
                Log.e(">>>>>DDDD>>vvvv>>","======"+thisAnswer);
                for(int j=0;j<Control.backSum(thisAnswer,"$、")+1;j++){
                    Log.e(">>>>>DDDD>>789>>", "==thisStuAssess====:"+Control.returnArray(thisStuAssess, "$、", 2)[j]);
                    if(!Control.returnArray(thisStuAssess, "$、", 2)[j].equals("")){
                        if(Control.returnArray(thisStuAssess,"$、",2)[j].equals("正确")){
                            totalItemCountTrue++;
                        }
                    }else{
                        Log.e(">>>>>DDDD>>777>>", "==thisStuAnswer==999==:"+Control.returnArray(thisStuAnswer, "$、", 2)[j].trim());
                        for(int b=0;b<Control.backSum(Control.returnArray(thisAnswer,"$、",2)[j],"$/")+1;b++) {
                            Log.e(">>>>>DDDD>>222>>", "==thisStuAnswer==999==:"+Control.returnArray(thisStuAnswer, "$、", 2)[j].trim());
                            Log.e(">>>>>DDDD>>333>>", "==thisStuAnswer==888==:"+ Control.returnArray(Control.returnArray(thisAnswer,"$、",2)[j],"$/",2)[b]);
                            if (Control.returnArray(thisStuAnswer, "$、", 2)[j].trim().equals( Control.returnArray(Control.returnArray(thisAnswer,"$、",2)[j],"$/",2)[b])) {
                                totalItemCountTrue++;
                            }

                        }
                    }
                }
            }
            InforBasicReview.getPaperContent().get(Position).setCorrectRate(Control.getCorrectRate(Float.valueOf(totalItemCountTrue),Float.valueOf(allSmallQuesItemTotalCount)));
        }
        PaperInfor.CorrectRate = InforBasicReview.getPaperContent().get(Position).getCorrectRate();
        PaperInfor.QuesAnsweredItemCount = InforBasicReview.getPaperContent().get(Position).getAnsweredItemCount();//试题小题数
        PaperInfor.PrimitiveQuesID = InforBasicReview.getPaperContent().get(Position).getQuesID();

        if(!PaperInfor.StuAnswerNewAll.equals(PaperInfor.StuAnswerOldAll)||!PaperInfor.StuAssessNewAll.equals(PaperInfor.StuAssessOldAll)){

            InforBasicReview.setState(1);
            PaperInfor.State = InforBasicReview.getState();

            int paperAnsweredItemCount = 0;
            for(int i=0;i<InforBasicReview.getPaperContent().size();i++){
                paperAnsweredItemCount = paperAnsweredItemCount + InforBasicReview.getPaperContent().get(i).getAnsweredItemCount();
            }

            InforBasicReview.setAnsweredItemCount(paperAnsweredItemCount);
            PaperInfor.PaperAnsweredItemCount =  InforBasicReview.getAnsweredItemCount();
            InforBasicReview.setDuration(paperTimeLong);
            PaperInfor.PaperDuration =  paperTimeLong;

            saveSingleQues(isFromExit);//答案不同或自评不同就保存作答结果
            InforBasicReview.getPaperContent().get(Position).setStuAnswerOldAll(PaperInfor.StuAnswerNewAll);
            PaperInfor.StuAnswerOldAll = PaperInfor.StuAnswerNewAll;
            InforBasicReview.getPaperContent().get(Position).setStuAssessOldAll(PaperInfor.StuAssessNewAll);
            PaperInfor.StuAssessOldAll = PaperInfor.StuAssessNewAll;
        }
    }


    /*
    * 提交
    * */
    public  List<SubmitDataJson> addTestPaperInfor(){

        List<SubmitDataJson> jsonTestPaper = new ArrayList<SubmitDataJson>();
        for(int k =0;k<InforBasicReview.getPaperContent().size();k++){

            PaperInfor.Score = InforBasicReview.getPaperContent().get(k).getScore();
//            PaperInfor.IsAssess = InforBasicReview.getPaperContent().get(k).getQueList().get(0).getIsAssess();
            if(!InforBasicReview.getPaperContent().get(k).getTheme().equals("")) {
                PaperInfor.QuesBrief = InforBasicReview.getPaperContent().get(k).getTheme();
            }else{
                PaperInfor.QuesBrief = InforBasicReview.getPaperContent().get(k).getQueList().get(0).getItemContent();
            }
            PaperInfor.QuesTotalItemCount = InforBasicReview.getPaperContent().get(k).getTotalItemCount();
            PaperInfor.TypeID = InforBasicReview.getPaperContent().get(k).getTypeID();
            int sumImportantZSDCode = InforBasicReview.getPaperContent().get(k).getImpKlg().size();
            String ImportantZSDCodeAll = "";
            String ImportantZSDAll = "";
            for(int i=0;i<sumImportantZSDCode;i++){
                if(i==0){
                    ImportantZSDCodeAll = InforBasicReview.getPaperContent().get(k).getImpKlg().get(i).getCode();
                    ImportantZSDAll = InforBasicReview.getPaperContent().get(k).getImpKlg().get(i).getName();
                }else {
                    ImportantZSDCodeAll = ImportantZSDCodeAll + "|" + InforBasicReview.getPaperContent().get(k).getImpKlg().get(i).getCode();
                    ImportantZSDAll = ImportantZSDAll + "|" + InforBasicReview.getPaperContent().get(k).getImpKlg().get(i).getName();
                }
            }
            PaperInfor.ImportantZSDCode = ImportantZSDCodeAll;
            PaperInfor.ImportantZSD = ImportantZSDAll;
            int sumMainZSDCode = InforBasicReview.getPaperContent().get(k).getMainKlg().size();
            String MainZSDCodeAll = "";
            String MainZSDAll = "";
            for(int i=0;i<sumMainZSDCode;i++){
                if(i==0){
                    MainZSDCodeAll = InforBasicReview.getPaperContent().get(k).getMainKlg().get(i).getCode();
                    MainZSDAll = InforBasicReview.getPaperContent().get(k).getMainKlg().get(i).getName();
                }else {
                    MainZSDCodeAll = MainZSDCodeAll + "|" + InforBasicReview.getPaperContent().get(k).getMainKlg().get(i).getCode();
                    MainZSDAll = MainZSDAll + "|" + InforBasicReview.getPaperContent().get(k).getMainKlg().get(i).getName();
                }
            }
            PaperInfor.MainZSDCode = MainZSDCodeAll;
            PaperInfor.MainZSD = MainZSDAll;
            PaperInfor.Difficulty = InforBasicReview.getDifficulty();
            PaperInfor.TestProbablity = 0.5;
            PaperInfor.StuName = UserInfo.StuName;
            int QuesDuration = paperTimeLong-InforBasicReview.getDuration()+InforBasicReview.getPaperContent().get(k).getDuration();//暂时瞎传
            InforBasicReview.getPaperContent().get(k).setDuration(QuesDuration);
            PaperInfor.QuesDuration = InforBasicReview.getPaperContent().get(k).getDuration();
            PaperInfor.QuesID = InforBasicReview.getPaperContent().get(k).getQuesID();

            PaperInfor.QuesAnsweredItemCount = InforBasicReview.getPaperContent().get(k).getAnsweredItemCount();
            if(getQuesType(k).equals("作文")||getQuesType(k).equals("看图写句子")||getQuesType(k).equals("翻译题")){

                PaperInfor.IsAssess = InforBasicReview.getPaperContent().get(k).getQueList().get(0).getIsAssess();

//                if(!InforBasicReview.getPaperContent().get(k).getQueList().get(0).getStuAssess().equals("")){

                    if(InforBasicReview.getPaperContent().get(k).getQueList().get(0).getStuAssess().equals("")){
                        InforBasicReview.getPaperContent().get(k).getQueList().get(0).setStuAssess("优秀");
                        PaperInfor.CorrectRate = 1.0;
                    }else if(InforBasicReview.getPaperContent().get(k).getQueList().get(0).getStuAssess().equals("优秀")||
                            InforBasicReview.getPaperContent().get(k).getQueList().get(0).getStuAssess().equals("一般")){
                        PaperInfor.CorrectRate = 1.0;
                    }else{
                        PaperInfor.CorrectRate = 0.0;
                    }

                    InforBasicReview.getPaperContent().get(k).setCorrectRate(PaperInfor.CorrectRate);
                    PaperInfor.QuesAnsweredItemCount = 1;
                    InforBasicReview.getPaperContent().get(k).setAnsweredItemCount(1);

//                }
                PaperInfor.StuAssessNewAll = InforBasicReview.getPaperContent().get(k).getQueList().get(0).getStuAssess();
                if(PaperInfor.StuAssessNewAll.equals("")){
                    InforBasicReview.getPaperContent().get(k).getQueList().get(0).setStuAssess("优秀");
                    PaperInfor.StuAssessNewAll = "优秀";
                }
                PaperInfor.StuAnswerNewAll = InforBasicReview.getPaperContent().get(k).getQueList().get(0).getStuAnswer();
            }else if(getQuesType(k).equals("阅读简答")||getQuesType(k).equals("听力简答")){
                int rightAnswer = 0;
                String stuAnswerAll = "";
                String stuAssessAll = "";
                for(int i =0 ;i<InforBasicReview.getPaperContent().get(k).getQueList().size();i++){
                    if(InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAssess().equals("")){
                        InforBasicReview.getPaperContent().get(k).getQueList().get(i).setStuAssess("优秀");
                        rightAnswer++;
                    }else{
                        if(!InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAssess().equals("较差")){
                            rightAnswer++;
                        }
                    }
                    if(i==0){
                        stuAnswerAll = InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAnswer();
                        if(stuAssessAll.equals("")){
                            InforBasicReview.getPaperContent().get(k).getQueList().get(i).setStuAssess("优秀");
                            stuAssessAll= "优秀";
                        }
                        stuAssessAll = InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAssess();
                        PaperInfor.IsAssess = InforBasicReview.getPaperContent().get(k).getQueList().get(0).getIsAssess();
                    }else {
                        stuAnswerAll = stuAnswerAll + "#$*#" + InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAnswer();
                        if(InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAssess().equals("")){
                            InforBasicReview.getPaperContent().get(k).getQueList().get(i).setStuAssess("优秀");
                        }
                        stuAssessAll = stuAssessAll + "#$*#" + InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAssess();
                        PaperInfor.IsAssess = PaperInfor.IsAssess+ "#$*#" +InforBasicReview.getPaperContent().get(k).getQueList().get(i).getIsAssess();
                    }
                }
                PaperInfor.CorrectRate = Control.getCorrectRate(rightAnswer,InforBasicReview.getPaperContent().get(k).getQueList().size());
                InforBasicReview.getPaperContent().get(k).setCorrectRate(PaperInfor.CorrectRate);
                PaperInfor.StuAnswerNewAll = stuAnswerAll;
                PaperInfor.StuAssessNewAll = stuAssessAll;
                InforBasicReview.getPaperContent().get(k).setAnsweredItemCount( InforBasicReview.getPaperContent().get(k).getQueList().size());
                PaperInfor.QuesAnsweredItemCount = InforBasicReview.getPaperContent().get(k).getAnsweredItemCount();
            }else{

                int totalItemCountTrue = 0;
                int allSmallQuesItemTotalCount = 0;
                String stuAnswerAll = "";
                String stuAssessAll = "";
                Log.e("=====stuanswer===","==size==="+InforBasicReview.getPaperContent().get(k).getQueList().size());
                for(int i =0 ;i<InforBasicReview.getPaperContent().get(k).getQueList().size();i++){
                    if(i==0){
                        stuAnswerAll = InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAnswer();
                        stuAssessAll = InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAssess();
                        String strStuAnswerAll = "";
                        if(stuAnswerAll.equals("")){
                            for(int a=0;a<Control.backSum(InforBasicReview.getPaperContent().get(k).getQueList().get(i).getAnswer(),"$、");a++){
                                strStuAnswerAll = strStuAnswerAll+"$、";
                            }
                        }else{
                            strStuAnswerAll = InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAnswer();
                        }
                        InforBasicReview.getPaperContent().get(k).getQueList().get(i).setStuAnswer(strStuAnswerAll);
                        stuAnswerAll = strStuAnswerAll;

                        String strStuAssessAll = "";
                        if(stuAssessAll.equals("")){
                            for(int a=0;a<Control.backSum(InforBasicReview.getPaperContent().get(k).getQueList().get(i).getAnswer(),"$、");a++){
                                strStuAssessAll = strStuAssessAll+"$、";
                            }
                        }else{
                            strStuAssessAll = InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAssess();
                        }
                        InforBasicReview.getPaperContent().get(k).getQueList().get(i).setStuAssess(strStuAssessAll);
                        stuAssessAll = strStuAssessAll;
                        PaperInfor.IsAssess = InforBasicReview.getPaperContent().get(k).getQueList().get(0).getIsAssess();
                    }else {
                        String strStuAnswerAll = "";
                        if(InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAnswer().equals("")){
                            for(int a=0;a<Control.backSum(InforBasicReview.getPaperContent().get(k).getQueList().get(i).getAnswer(),"$、");a++){
                                strStuAnswerAll = strStuAnswerAll+"$、";
                            }
                        }else{
                            strStuAnswerAll = InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAnswer();
                        }
                        InforBasicReview.getPaperContent().get(k).getQueList().get(i).setStuAnswer(strStuAnswerAll);
                        stuAnswerAll = stuAnswerAll + "#$*#" +strStuAnswerAll;

                        String strStuAssessAll = "";
                        if(InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAssess().equals("")){
                            for(int a=0;a<Control.backSum(InforBasicReview.getPaperContent().get(k).getQueList().get(i).getAnswer(),"$、");a++){
                                strStuAssessAll = strStuAssessAll+"$、";
                            }
                        }else{
                            strStuAssessAll = InforBasicReview.getPaperContent().get(k).getQueList().get(i).getStuAssess();
                        }
                        InforBasicReview.getPaperContent().get(k).getQueList().get(i).setStuAssess(strStuAssessAll);
                        stuAssessAll = stuAssessAll + "#$*#" +strStuAssessAll;
                        PaperInfor.IsAssess = PaperInfor.IsAssess+ "#$*#" +InforBasicReview.getPaperContent().get(k).getQueList().get(i).getIsAssess();
                    }

                    String thisStuAnswer = "";
                    String thisAnswer = "";
                    String thisStuAssess = "";
                    int totalThisItemCount = InforBasicReview.getPaperContent().get(k).getQueList().size();
                    for(int c=0;c<totalThisItemCount;c++) {
                        allSmallQuesItemTotalCount = allSmallQuesItemTotalCount + Control.backSum(
                                InforBasicReview.getPaperContent().get(k).getQueList().get(c).getAnswer(), "$、") + 1;
                    }
                    for(int a=0;a<totalThisItemCount;a++){
                        thisStuAnswer = InforBasicReview.getPaperContent().get(k).getQueList().get(a).getStuAnswer();
                        thisAnswer = InforBasicReview.getPaperContent().get(k).getQueList().get(a).getAnswer();
                        thisStuAssess = InforBasicReview.getPaperContent().get(k).getQueList().get(a).getStuAssess();
                        Log.e(">>>>>DDDD>>vvvv>>","======"+thisAnswer);
                        for(int j=0;j<Control.backSum(thisAnswer,"$、")+1;j++){
                            Log.e(">>>>>DDDD>>789>>", "==thisStuAssess====:"+Control.returnArray(thisStuAssess, "$、", 2)[j]);
                            if(!Control.returnArray(thisStuAssess, "$、", 2)[j].equals("")){
                                if(Control.returnArray(thisStuAssess,"$、",2)[j].equals("正确")){
                                    totalItemCountTrue++;
                                }
                            }else{
                                Log.e(">>>>>DDDD>>777>>", "==thisStuAnswer==999==:"+Control.returnArray(thisStuAnswer, "$、", 2)[j].trim());
                                for(int b=0;b<Control.backSum(Control.returnArray(thisAnswer,"$、",2)[j],"$/")+1;b++) {
                                    Log.e(">>>>>DDDD>>222>>", "==thisStuAnswer==999==:"+Control.returnArray(thisStuAnswer, "$、", 2)[j].trim());
                                    Log.e(">>>>>DDDD>>333>>", "==thisStuAnswer==888==:"+ Control.returnArray(Control.returnArray(thisAnswer,"$、",2)[j],"$/",2)[b]);
                                    if (Control.returnArray(thisStuAnswer, "$、", 2)[j].trim().equals( Control.returnArray(Control.returnArray(thisAnswer,"$、",2)[j],"$/",2)[b])) {
                                        totalItemCountTrue++;
                                    }

                                }
                            }
                        }
                    }
                }

                PaperInfor.CorrectRate = Control.getCorrectRate((float)totalItemCountTrue,(float)allSmallQuesItemTotalCount);
                PaperInfor.StuAnswerNewAll = stuAnswerAll;
                PaperInfor.StuAssessNewAll = stuAssessAll;
                PaperInfor.QuesAnsweredItemCount = InforBasicReview.getPaperContent().get(k).getAnsweredItemCount();
            }

            PaperInfor.State = 2;

            int paperAnsweredItemCount = 0;
            for(int i=0;i<InforBasicReview.getPaperContent().size();i++){
                paperAnsweredItemCount = paperAnsweredItemCount + InforBasicReview.getPaperContent().get(i).getAnsweredItemCount();
            }
            InforBasicReview.setAnsweredItemCount(paperAnsweredItemCount);
            PaperInfor.PaperAnsweredItemCount =  InforBasicReview.getAnsweredItemCount();
            InforBasicReview.setDuration(paperTimeLong);
            PaperInfor.PaperDuration =  paperTimeLong;
            PaperInfor.PrimitiveQuesID = InforBasicReview.getPaperContent().get(k).getQuesID();
            Log.e("=====提交==11===","==="+getQuesType(k)+"===自评=="+ PaperInfor.StuAssessNewAll);
            Log.e("=====提交==88===","==="+getQuesType(k)+"===我的答案=="+ PaperInfor.StuAnswerNewAll);
            jsonTestPaper.add(DataPackage.getSubmitDataJson(UserInfo.StuId,UserInfo.SubjectId,UserInfo.StageNo,PaperInfor.QuesID,PaperInfor.State,
                    PaperInfor.Score,PaperInfor.IsAssess,PaperInfor.QuesBrief,PaperInfor.QuesTotalItemCount,PaperInfor.QuesFrom,PaperInfor.TypeID,
                    PaperInfor.ImportantZSDCode,PaperInfor.MainZSDCode,PaperInfor.ImportantZSD,PaperInfor.MainZSD,PaperInfor.Difficulty,PaperInfor.TestProbablity,
                    PaperInfor.StuName,PaperInfor.PaperID,PaperInfor.StuAnswerNewAll,PaperInfor.StuAssessNewAll,PaperInfor.QuesDuration,PaperInfor.CorrectRate,
                    PaperInfor.QuesAnsweredItemCount,PaperInfor.PrimitiveQuesID));
        }
        PaperInfor.ListSubmitDataJson = jsonTestPaper;
        return jsonTestPaper;
    }

    /*******************************************************************************************************************************/
    /*******************************************************************************************************************************/
    /*******************************************************************************************************************************/


}